﻿using ZhiAo.BaseFramework.Library;
using System;
using System.Data;

namespace ZhiAo.BaseFramework.DBConnection
{
    public class TCtlDB : IDB
    {
        public static DB FDB;

        public TCtlDB()
        {
            try
            {
                FDB = new DB();
            }
            catch (Exception exception)
            {
                throw new  Exception(exception.Message);
            }
        }


        public bool Execute(string SQL)
        {
            bool flag = FDB.Execute(SQL);
            if (!flag)
            {
                throw new Exception(this.ErrMessage);
            }
            return flag;
        }

        public DataSet GetDataSet(string SQL)
        {
            DataSet dataSet = FDB.GetDataSet(SQL);
            if (dataSet == null)
            {
                throw new Exception(this.ErrMessage);
            }
            return dataSet;
        }

        public DataSet GetDataSet(string SQL, string strAlias)
        {
            DataSet dataSet = FDB.GetDataSet(SQL, strAlias);
            if (dataSet == null)
            {
                throw new Exception(this.ErrMessage);
            }
            return dataSet;
        }

        public DataTable GetDataTable(string SQL, string strAlias)
        {
            DataTable dataTable = FDB.GetDataTable(SQL, strAlias);
            if (dataTable == null)
            {
                throw new Exception(this.ErrMessage);
            }
            return dataTable;
        }

        public DataView GetDataView(string SQL)
        {
            DataView dataView = FDB.GetDataView(SQL);
            if (dataView == null)
            {
                throw new Exception(this.ErrMessage);
            }
            return dataView;
        }

        public string GetFieldValue(string SQL)
        {
            return FDB.GetFieldValue(SQL);
        }

        public DB DBEntity
        {
            get
            {
                return FDB;
            }
        }

        public string ErrMessage
        {
            get
            {
                return FDB.ErrMessage;
            }
        }
    }
}

